$(function (){
    var argumentsRobot=["实时功率","电池电压","剩余电量百分比","机器人运行速度","设备温度"];
    var argValuesRobot=["realTimePower","batteryVtage","batteryPct","robotSpd","robotTmpr"];
    var argumentsEnvironment=["温度","甲烷浓度","风速","氧气浓度","二氧化碳浓度","一氧化碳浓度"];
    var argValuesEnvironment=["envTmpr","methane","windSpd","O2","CO2","CO1"];
    var argumentsDevice=["电机温度","环境温度","轴承温度","输入端轴承震动","减速机输出"];
    var argValuesDevice=["motorTmpr","envTmpr","bearingTmpr","inputBearVbrte","reducerOutput"];
    $('#selectDevice').change(function() {
        // console.log($(this).val());
        var dbName=$(this).val();
        var arguments;
        var argValues;
        if(dbName=="robotworkinglogentity"){
            arguments=argumentsRobot;
            argValues=argValuesRobot;
        }else if(dbName=="environmentlogentity"){
            arguments=argumentsEnvironment;
            argValues=argValuesEnvironment;
        }else if(dbName=="deviceworkinglogentity"){
            arguments=argumentsDevice;
            argValues=argValuesDevice;
        }
        // console.log(arguments)
        var selectArgument=$("#selectArgument");
        $("#checkArg").empty();
        for(var i=0;i<arguments.length;i++){
            // $("#selectArgument").append("<option value='"+i+"'>"+arguments[i]+"</option>");
            $("#checkArg").append("<label class='checkbox-inline'><input type='checkbox' name='chkArgVal' value='"+argValues[i]+"'>"+arguments[i]+"</label>")
        }
    })


    
    $("#searchButton").click(function () {
        var chkArgVal=new Array();
        var i=0;
        $("input[name='chkArgVal']:checkbox:checked").each(function(){
            chkArgVal[i++]=$(this).val();
        })
        var tableVal=$("#selectDevice").val();
        var beginTimeVal=$("#beginTimeVal").val();
        var endTimeVal=$("#endTimeVal").val();
        $.ajax({
            url:"TableQuery",
            traditional:true,
            data:{
                "tableVal":tableVal,
                "beginTimeVal":beginTimeVal,
                "endTimeVal":endTimeVal,
                "chkArgVal":chkArgVal
            },
            success:function (results) {
                console.log(results)
                console.log(results.name)
                // window.location.reload();
                var domPower = document.getElementById("container");
                var myChartPower = echarts.init(domPower);
                var app = {};
                var len=results[0].data.length;
                var length=new Array();
                for(var j=0;j<len;j++){
                    length[j]=j+1;
                }

                var optionPower;
                optionPower = {
                    title: {
                        text: '历史数据查询'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data:results.name
                    },
                    grid: {
                        // left: '3%',
                        // right: '4%',
                        // bottom: '3%',
                        containLabel: true
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data:length
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: results
                };

                myChartPower.setOption(optionPower);
            }
        })
    });
})


